package com.lijiankun24.shadowlayoutexample.slice;

import com.lijiankun24.shadowlayout.ShadowLayout;
import com.lijiankun24.shadowlayoutexample.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;

/**
 * 更改阴影效果展示类
 *
 * @author lijiankun
 * @since 2021-03-08
 */
public class DynamicChangeAbilitySlice extends AbilitySlice {
    private static final float RADIUS = 10f;
    private static final float DEFAULT_RADIUS = 20f;

    /**
     * onStart
     *
     * @param intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_dynamic_change);

        initComponent();
    }

    private void initComponent() {
        ShadowLayout slOval = (ShadowLayout) findComponentById(ResourceTable.Id_sl_oval);
        ShadowLayout slRectangle = (ShadowLayout) findComponentById(ResourceTable.Id_sl_rectangle);
        ShadowLayout slRadius = (ShadowLayout) findComponentById(ResourceTable.Id_sl_radius);
        slOval.setShadowColor(Color.getIntColor("#FE3311F3"));
        slRectangle.setShadowColor(Color.getIntColor("#EE000000"));
        slRadius.setShadowRadius(DEFAULT_RADIUS);
        Text textOval = (Text) findComponentById(ResourceTable.Id_text_oval);
        Text textRectangle = (Text) findComponentById(ResourceTable.Id_text_rectangle);
        Text textRadius = (Text) findComponentById(ResourceTable.Id_text_radius);

        textOval.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                slOval.setShadowColor(Color.getIntColor("#FEFFD700"));
            }
        });
        textRectangle.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                slRectangle.setShadowColor(Color.getIntColor("#EE00FF7F"));
            }
        });

        textRadius.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                slRadius.setShadowRadius(RADIUS);
            }
        });
    }

    /**
     * onActive
     */
    @Override
    public void onActive() {
        super.onActive();
    }

    /**
     * onForeground
     *
     * @param intent
     */
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
